#!/bin/bash
#
# Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# Update plymouth for ssd drivers.

DI_ROOT_PARTITION=$(installer_get "DI_ROOT_PARTITION")

detect_rootblk() {
  if [ ! -z ${DI_ROOT_PARTITION} ]; then
    local PDEVICE
    PDEVICE=$(stat -c "%02t" ${DI_ROOT_PARTITION})
    for file in $(find /dev -type b 2>/dev/null); do
      local CURRENT_DEVICE
      CURRENT_DEVICE=$(stat -c "%02t%02T" $file)
      if [ x"$CURRENT_DEVICE" = x"${PDEVICE}00" ]; then
        ROOTBLK=${file##*/}
      fi
    done
  fi
}

detect_solid() {
  FILEPATH=/sys/block/${ROOTBLK}/queue/rotational
  [ -e ${FILEPATH} ] && read CHECK < ${FILEPATH}
  [ -n $CHECK ] && [ x$CHECK = "x0" ] && return 0
  return 1
}

update_plymouth() {
  if [ -e /usr/share/plymouth/themes/deepin-ssd-logo ] && detect_solid; then
  	plymouth-set-default-theme deepin-ssd-logo
  fi
}

detect_rootblk 
[ -n $ROOTBLK ] && update_plymouth

return 0
